added SSCLI 1.0
[windows-sources.git] / shared source / sscli20 / tools / nmake / utilp.cpp
blob8fca75576a5d74abeb90f7bc4d93c8b712d6374f
1 // ==++==
2 //
3 //
4 // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
5 //
6 // The use and distribution terms for this software are contained in the file
7 // named license.txt, which can be found in the root of this distribution.
8 // By using this software in any fashion, you are agreeing to be bound by the
9 // terms of this license.
10 //
11 // You must not remove this notice, or any other, from this software.
12 //
14 // ==--==
15 // UTILB.C -- Data structure manipulation functions specific to OS/2
17 // Purpose:
18 // This file was created from functions in util.c & esetdrv.c which were system
19 // dependent. This was done so that the build of the project became simpler and
20 // there was a clear flow in the build process.
22 // Method of Creation:
23 // 1. Identified all functions having mixed mode code.
24 // 2. Deleted all code blocked out by '#ifndef BOUND' preprocessor directives
25 // in these functions
26 // 3. Deleted all local function & their prototypes not referred by these
27 // 4. Deleted all global data unreferenced by these, including data blocked
28 // of by '#ifdef DEBUG'
30 #include "precomp.h"
31 #ifdef _MSC_VER
32 #pragma hdrstop
33 #endif
36 STRINGLIST *
37 expandWildCards(
38 char *s // text to expand
41 struct _finddata_t finddata;
42 NMHANDLE searchHandle;
43 STRINGLIST *xlist, // list of expanded names
44 *p;
45 char *namestr;
47 if (!(namestr = findFirst(s, &finddata, &searchHandle))) {
48 return(NULL);
51 xlist = makeNewStrListElement();
52 xlist->text = prependPath(s, namestr);
54 while ((namestr = findNext(&finddata, searchHandle))) {
55 p = makeNewStrListElement();
56 p->text = prependPath(s, namestr);
57 prependItem(&xlist, p);
60 return(xlist);
64 // QueryFileInfo -- it does a DosFindFirst which circumvents FAPI restrictions
66 // Scope: Global (used by Build.c also)
68 // Purpose:
69 // DosFindFirst() has a FAPI restriction in Real mode. You cannot ask it give
70 // you a handle to a DTA structure other than the default handle. This function
71 // calls C Library Function _dos_findfirst in real mode (which sets the DTA) and
72 // does the job. In protect mode it asks OS/2 for a new handle.
74 // Input:
75 // file -- the file to be searched for
76 // dta -- the struct containing result of the search
78 // Output: Returns a pointer to the filename found (if any)
80 // Assumes: That dta points to a structure which has been allocated enough memory
82 // Uses Globals:
83 // _osmode -- to determine whether in Real or Bound mode
85 char *
86 QueryFileInfo(
87 char *file,
88 void **dta
91 NMHANDLE hDir;
92 char *t;
94 // Remove Quotes around filename, if existing
95 t = file + _tcslen(file) - 1;
96 if (*file == '"' && *t == '"') {
97 file = unQuote(file); // file is quoted, so remove quote
101 if ((hDir = _findfirst(file, (struct _finddata_t *) dta)) == -1) {
102 return(NULL);
105 _findclose(hDir);
107 return(((struct _finddata_t *) dta)->name);
112 // Truncate filename to system limits
114 void
115 truncateFilename(
116 char * s
119 char szDrive[_MAX_DRIVE];
120 char szDir[_MAX_DIR];
121 char szName[_MAX_FNAME];
122 char szExtension[_MAX_EXT];
124 // pathname incorrectly truncated. Solution: first parse it
125 // using _splitpath(), then truncate the filename and extension part.
126 // Finally reconstruct the pathname by calling _makepath().
128 _splitpath(s, szDrive, szDir, szName, szExtension);
129 _makepath(s, szDrive, szDir, szName, szExtension);
133 char *
134 findFirst(
135 char *s, // text to expand
136 void *dta,
137 NMHANDLE *dirHandle
140 BOOL anyspecial; // flag set if s contains special characters.
141 char buf[_MAX_PATH]; // buffer for removing ESCH
143 // Check if name contains any special characters
145 anyspecial = (_tcspbrk(s, "\"^*?") != NULL);
147 if (anyspecial) {
148 char *t;
149 char *x; // Pointers for truncation, walking for ESCH
151 t = s + _tcslen(s) - 1;
153 // Copy pathname, skipping ESCHs and quotes
154 x = buf;
155 while( *s ) {
156 if (*s == '^' || *s == '"') {
157 s++;
159 else {
160 if (_istlead(*(unsigned char *)s))
161 *x++ = *s++;
162 *x++ = *s++;
166 *x = '\0';
167 s = buf; // only elide ESCH the first time!
170 truncateFilename(s);
172 if ((*dirHandle = _findfirst(s, (struct _finddata_t *) dta)) == -1) {
173 return(NULL);
176 // If it had no wildcard then close the search handle
178 if (!anyspecial || (!_tcschr(s, '*') && !_tcschr(s, '?'))) {
179 _findclose(*dirHandle);
182 return(((struct _finddata_t *) dta)->name);
185 char *
186 findNext(
187 void *dta,
188 NMHANDLE dirHandle
191 if (_findnext(dirHandle, (struct _finddata_t *) dta)) {
192 _findclose(dirHandle);
194 return(NULL);
197 return(((struct _finddata_t *) dta)->name);
201 char *
202 getCurDir(void)
204 // Convert $ to $$ before returning current dir
205 // This allows $(MAKEDIR) to work properly in
206 // case the current path contains a $ sign.
208 char *pszPath;
209 char pbPath[_MAX_DIR+1];
210 char *pchSrc = pbPath;
211 char *pchDst;
212 char ch;
214 GetCurrentDirectoryA(_MAX_DIR+1, pbPath);
215 pszPath = (char *) rallocate(2 * _tcslen(pbPath) + 1);
217 pchDst = pszPath;
219 // non-MBCS aware implementation ('$' can't be a trailbyte)
220 while ((ch = *pchSrc)) {
221 *pchDst++ = *pchSrc++;
222 if ('$' == ch)
223 *pchDst++ = ch;
225 *pchDst = '\0';
227 return(pszPath);
231 void
232 curTime(
233 time_t *plTime
236 time(plTime);